package com.zzz.common;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class RspResult<T> implements Serializable {
    // 通用状态码
    public static final Integer SUCESS_CODE = 200;
    public static final Integer ERROR_CODE = 500;

    private Integer code;
    private String message;
    private Object data;

    private RspResult() {

    }

    public static <T> RspResult<T> ok(String message) {
        return new RspResult<T>().setCode(SUCESS_CODE).setMessage(message);
    }

    public static <T> RspResult<T> ok(T t) {
        return new RspResult<T>().setCode(SUCESS_CODE).setData(t);
    }

    public static <T> RspResult<T> fail(String message) {
        return new RspResult<T>().setCode(ERROR_CODE).setMessage(message);
    }

    public static <T> RspResult<T> fail(Integer code, String message) {
        return new RspResult<T>().setCode(code).setMessage(message);
    }

}
